package org.lex.app.prefs;

abstract class AbstractResourceMap implements ResourceMap {
	protected static final char SEPARATOR = ',';

	public abstract String getString(String key);

	public abstract void putString(String key, String value);

	public void putProperty(String key, Object value) {
		this.putString(key, null == value ? "" : value.toString());
	}

	public boolean getBoolean(String key) {
		return this.getBoolean(key, false);
	}

	public boolean getBoolean(String key, boolean defaultValue) {
		String value = this.getString(key);
		return value == null ? defaultValue : Boolean.parseBoolean(value);
	}

	public double getDouble(String key) {
		return this.getDouble(key, 0.0D);
	}

	public double getDouble(String key, double defaultValue) {
		String v = this.getString(key);
		return null == v ? defaultValue : Double.parseDouble(v);
	}

	public float getFloat(String key) {
		return this.getFloat(key, 0.0F);
	}

	public float getFloat(String key, float defaultValue) {
		String v = this.getString(key);
		return null == v ? defaultValue : Float.parseFloat(v);
	}

	public int getInt(String key) {
		return this.getInt(key, 0);
	}

	public int getInt(String key, int defaultValue) {
		String v = this.getString(key);
		return v == null ? defaultValue : Integer.parseInt(v);
	}

	public long getLong(String key) {
		return this.getLong(key, 0L);
	}

	public long getLong(String key, long defaultValue) {
		String v = this.getString(key);
		return null == v ? defaultValue : Long.parseLong(v);
	}

	public String getString(String key, String defaultValue) {
		String value = this.getString(key);
		return value == null ? defaultValue : value;
	}
}
